export default class barrier3 extends Laya.Script {

    constructor() { super(); }
    private off: Laya.Sprite     //触发开关
    private barrier1: Laya.Sprite     //机关门1
    private barrier2: Laya.Sprite     //机关门2
    private b_state: boolean

    onEnable(): void {
        //初始化变量
        this.initParams()
    }


    onTriggerEnter(other: Laya.ColliderBase, self: any) {
        if (other.label == "player1" || other.label == "player2") {
            //触发开关
            Laya.Tween.to(
                this.off,
                { y: 1.5 },
                1000,
                Laya.Ease.strongInOut)
            //机关门1
            Laya.Tween.to(
                this.barrier1,
                { y: 750 },
                1000,
                Laya.Ease.strongInOut)
            //机关门2
            Laya.Tween.to(
                this.barrier2,
                { y: 750 },
                1000,
                Laya.Ease.strongInOut)

            //延时
            Laya.timer.once(1800, this, () => {
                Laya.Tween.to(
                    this.off,
                    { y: 1.5 },
                    800,
                    Laya.Ease.strongInOut,
                    Laya.Handler.create(this, () => {
                        // Laya.timer.once()
                        Laya.Tween.to(
                            this.off,
                            { y: -30 },
                            1000,
                            Laya.Ease.strongInOut)
                    })
                )

                Laya.Tween.to(
                    this.barrier1,
                    { y: 750 },
                    800,
                    Laya.Ease.strongInOut,
                    Laya.Handler.create(this, () => {
                        // Laya.timer.once()
                        Laya.Tween.to(
                            this.barrier1,
                            { y: 410 },
                            1000,
                            Laya.Ease.strongInOut)
                    })
                )

                Laya.Tween.to(
                    this.barrier2,
                    { y: 750 },
                    800,
                    Laya.Ease.strongInOut,
                    Laya.Handler.create(this, () => {
                        // Laya.timer.once()
                        Laya.Tween.to(
                            this.barrier2,
                            { y: 410 },
                            1000,
                            Laya.Ease.strongInOut)
                    })
                )
            })

        }
        this.b_state = true
    }




    initParams() {
        this.off = this.owner.parent.getChildByName("off") as Laya.Sprite
        this.barrier1 = this.owner.parent.parent.getChildByName("barrier1") as Laya.Sprite
        this.barrier2 = this.owner.parent.parent.getChildByName("barrier2") as Laya.Sprite
    }

    onDisable(): void {

    }
}